﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using jiaju.Models;
using jiaju.Models.DBModel;
namespace jiaju.Models.DAL
{
    public class ProductTypeService
    {
        public static List<ProductType> GetProductType()
        {
            string sql = "select Id,Name from dbo.ProductType";
            SqlDataReader sdr = DBHelp.ExecuteReader(sql);
            List<ProductType> list = new List<ProductType>();
            while (sdr.Read())
            {
                int Id = (int)sdr["Id"];
                string Name = (string)sdr["Name"];
                ProductType ban = new ProductType()
                {
                    Id = Id,
                    Name = Name
                };
                list.Add(ban);
            }
            return list;
        }
        public Product GETById(int Id)
        {
            string sql = string.Format("select Id,Name,ImgUrl,Caizhi,ProductPrice,MarketPrice,Brand,XingHao,FengGe,Zuzhuang,Color,KuanShi,Cont from dbo.Product where Id={0}", Id);
            SqlDataReader sdr = DBHelp.ExecuteReader(sql);
            Product lsit = null;
            while (sdr.Read())
            {
                int id = (int)sdr["Id"];
                string Name = (string)sdr["Name"];
                string ImgUrl = (string)sdr["ImgUrl"];
                string CaiZhi = (string)sdr["CaiZhi"];
                Decimal ProductPrice = (Decimal)sdr["ProductPrice"];
                Decimal MarketPrice = (Decimal)sdr["MarketPrice"];
                string Brand = (string)sdr["Brand"];
                string XingHao = (string)sdr["XingHao"];
                string FengGe = (string)sdr["FengGe"];
                string ZuZhuang = (string)sdr["ZuZhuang"];
                string Color = (string)sdr["Color"];
                string KuanShi = (string)sdr["KuanShi"];
                string Cont = (string)sdr["Cont"];
                lsit = new Product()
                {
                    Id = id,
                    Name = Name,
                    ImgUrl = ImgUrl,
                    CaiZhi = CaiZhi,
                    ProductPrice = ProductPrice,
                    MarketPrice = MarketPrice,
                    Brand = Brand,
                    XingHao = XingHao,
                    FengGe = FengGe,
                    ZuZhuang = ZuZhuang,
                    Color = Color,
                    KuanShi = KuanShi,
                    Cont = Cont
                };
            };
            return lsit;
        }
        public static List<Picutre> getPicutre()
        {
            string sql = "select ImgUrl,ProductId from dbo.Picture";
            SqlDataReader sdr = DBHelp.ExecuteReader(sql);
            List<Picutre> list = new List<Picutre>();
            while (sdr.Read())
            {
                string ImgUrl = (string)sdr["ImgUrl"];
                int ProductId = (int)sdr["ProductId"];
                Picutre jkl = new Picutre()
                {

                    ImgUrl = ImgUrl,
                    ProductId = ProductId
                };
                list.Add(jkl);
            }
            return list;
        }
    }
}